package io.afu.nginxhelper.dto;

import io.afu.nginxhelper.constant.NgxConst;

import java.util.ArrayList;
import java.util.List;

public class ErrorPage {

    public static final String KEY = "error_page";

    private List<String> codes;

    private String pagePath;


    public ErrorPage addCode(String code) {
        if (this.codes == null){
            this.codes = new ArrayList<>();
        }
        codes.add(code);
        return this;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("error_page")
                .append(NgxConst.SEP);
        for (String code:codes){
            stringBuilder.append(code).append(NgxConst.SEP);
        }
        stringBuilder.append(this.pagePath).append(NgxConst.END_MARK);
        return stringBuilder.toString();
    }

    public List<String> getCodes() {
        return codes;
    }

    public void setCodes(List<String> codes) {
        this.codes = codes;
    }

    public String getPagePath() {
        return pagePath;
    }

    public void setPagePath(String pagePath) {
        this.pagePath = pagePath;
    }
}
